# vip用户
Vqueue = []
Vhead = 0
Vtail = 0
# normal用户
Nqueue = []
Nhead = 0
Ntail = 0

def inQueue(name,type): # 入队
    global Vqueue,Vhead,Vtail,Nqueue,Nhead,Ntail
    if type == 'V':
        Vqueue.append(name)
        Vtail +=1

    if type == 'N':
        Nqueue.append(name)
        Ntail +=1

def queueHead(type): # 取队头
    global Vqueue,Vhead,Vtail,Nqueue,Nhead,Ntail
    if type == 'V':
        return Vqueue[Vhead]

    if type == 'N':
        return Nqueue[Nhead]


def outQueue(type): # 出队
    global Vqueue,Vhead,Vtail,Nqueue,Nhead,Ntail
    if type == 'V':
        if Vhead == Vtail:
            return None
        else:
            Vhead +=1

    if type == 'N':
        if Nhead == Ntail:
            return None
        else:
            Nhead +=1

if __name__ == '__main__':
    M = int(input())
    for i in range(M):
        op = input().split()
        if op[0] == 'IN':
            inQueue(op[1],op[2])

        if op[0] == 'OUT':
            outQueue(op[1])
    for i in range(Vhead,Vtail):
        print(Vqueue[i])
    for i in range(Nhead,Ntail):
        print(Nqueue[i])
